package net.es.weathermap.topo.network;

import java.util.*;

import org.apache.log4j.Logger;

import net.es.oscars.client.improved.ConfigHelper;

/**
 * Singleton to store network information map.
 * @author David Robertson, Evangelos Chaniotakis
 */
public class NetworkInfo {

    private static NetworkInfo instance;
    private static final String DEFAULT_INFO_FILE = "network.yaml";

    private Logger log;
    private String network;
    private String delimiter;
    private ArrayList<String> metricServerUrls;

    /**
     * Constructor - private because this is a Singleton
     */
    private NetworkInfo() {
        this.log = Logger.getLogger(this.getClass());
    }

    /**
     * @return the initialized NetworkInfo singleton instance
     */
    public static NetworkInfo getInstance() {
        if (NetworkInfo.instance == null) {
            NetworkInfo.instance = new NetworkInfo();
            NetworkInfo.instance.setInfo(DEFAULT_INFO_FILE);
        }
        return NetworkInfo.instance;
    }

    public String getNetwork() {
        return this.network;
    }

    public String getDelimiter() {
        return this.delimiter;
    }

    public ArrayList<String> getMetricServerUrls() {
        return this.metricServerUrls;
    }

    private void setInfo(String fname) {
        ConfigHelper cfg = ConfigHelper.getInstance();
        Map yamlMap = cfg.getConfiguration(fname);
        assert yamlMap != null:  "Could not load soap configuration file from " +
            "file: ${basedir}/config/" + DEFAULT_INFO_FILE;
        this.network = (String) yamlMap.get("network");
        this.metricServerUrls = (ArrayList<String>) yamlMap.get("metricServerUrls");
        this.delimiter = (String) yamlMap.get("delimiter");
    }
}
